#!/bin/bash
# Finder double-click entry point. Installer opens in Terminal to request explicit consent.
set -euo pipefail
HERE="$(cd -- "$(dirname -- "$0")/.." && pwd -P)"
SCRIPT="$HERE/Resources/AyBTCMiner/Install_macOS.sh"
if [[ ! -r "$SCRIPT" ]]; then
    /usr/bin/osascript -e 'display alert "Ay BTC Miner" message "Installationsdateien fehlen. Bitte ZIP neu entpacken."' || true
    exit 2
fi
# Use AppleScript's 'quoted form of' to preserve paths with spaces/apostrophes.
if ! /usr/bin/osascript - "$SCRIPT" <<'APPLE'
on run args
    set installerPath to item 1 of args
    set launchCommand to "/bin/bash " & quoted form of installerPath
    tell application "Terminal"
        activate
        do script launchCommand
    end tell
end run
APPLE
then
    /usr/bin/osascript -e 'display alert "Ay BTC Miner" message "Terminal konnte nicht gestartet werden. Bitte README_MACOS.txt lesen."' || true
    exit 3
fi
